//
//  LGRecoveryTrainingCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/7.
//  训练项目Cell

#import "LGRecoveryTrainingCell.h"

@interface LGRecoveryTrainingCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *picView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGRecoveryTrainingCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.picView sd_setImageWithURL:[NSURL URLWithString:dataDic[@"cover_url"]]];
    self.titleLabel.text = [NSString stringWithFormat:@"%@·%@",dataDic[@"category_name"],dataDic[@"title"]];
    if(self.showDesc == YES){
        self.contentLabel.text = LGNSString(dataDic[@"description"]);
    }else{
        if([LGNSString(dataDic[@"duration"]) isEqualToString:@"无"]){
            self.contentLabel.text = [NSString stringWithFormat:@"共 %@ 组， 每组 %@ 次",dataDic[@"group_times"],dataDic[@"action_times"]];
        }else{
            self.contentLabel.text = [NSString stringWithFormat:@"共 %@ 组， 每组 %@ 次， 每次 %@ 秒",dataDic[@"group_times"],dataDic[@"action_times"],dataDic[@"duration"]];
        }
    }
    
}

-(void)setIndex:(NSInteger)index{
    _index = index;
    self.titleLabel.text = [NSString stringWithFormat:@"%.2ld %@·%@",index+1,self.dataDic[@"category_name"],self.dataDic[@"title"]];
}

-(void)setType:(NSString *)type{
    _type = type;
    if([type isEqualToString:@"top"]){
        self.baseView.cornerRidus = 15;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(0);
            make.bottom.equalTo(self.contentView).offset(15);
            make.height.equalTo(@(viewPix(93)));
        }];
    }else if ([type isEqualToString:@"middle"]){
        self.baseView.cornerRidus = 0;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(0);
            make.bottom.equalTo(self.contentView).offset(0);
            make.height.equalTo(@(viewPix(78)));
        }];
    }else if ([type isEqualToString:@"bottom"]){
        self.baseView.cornerRidus = 15;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(-15);
            make.bottom.equalTo(self.contentView).offset(0);
            make.height.equalTo(@(viewPix(98)));
        }];
    }else{
        self.baseView.cornerRidus = 15;
        [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(0);
            make.bottom.equalTo(self.contentView).offset(-viewPix(16));
            make.height.equalTo(@(viewPix(86)));
        }];
    }
}

-(void)setShowTip:(BOOL)showTip{
    _showTip = showTip;
    self.tipView.hidden = !showTip;
    CGFloat width = (showTip == YES)?viewPix(12):0;
    [self.tipView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.picView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.tipView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(0);
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.height.equalTo(@(viewPix(80)));
    }];
    [self.picView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(32));
        make.top.equalTo(self.contentView).offset(viewPix(12));
        make.width.equalTo(@(viewPix(99)));
        make.height.equalTo(@(viewPix(62)));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.picView).offset(viewPix(5));
        make.left.equalTo(self.picView.mas_right).offset(viewPix(12));
        make.right.equalTo(self.tipView.mas_left);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(8));
        make.left.right.equalTo(self.titleLabel);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(28));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self.picView);
    }];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#EFEFEF"];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UIImageView *)picView{
    if(!_picView){
        _picView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(12), viewPix(99), viewPix(62))];
        _picView.cornerRidus = 10;
    }
    return _picView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _contentLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
